﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net.Core;
using System.ComponentModel.Composition;
using log4net.Config;

namespace Psm.Logging.Log4netLogger
{   
    [Export(typeof(Psm.Logging.ILogger))]
    public class Log4netLogger : Psm.Logging.ILogger
    {
        static Log4netLogger()
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        private log4net.ILog _logger;

        public Log4netLogger()
        {
            _logger = log4net.LogManager.GetLogger(typeof(Log4netLogger));
        }

        public void Debug(string message, params object[] args)
        {
            if( _logger.IsDebugEnabled)
                _logger.DebugFormat(message, args);
        }

        public void Info(string message, params object[] args)
        {
            if (_logger.IsInfoEnabled)
                _logger.InfoFormat(message, args);
        }

        public void Warning(string message, params object[] args)
        {
            if( _logger.IsWarnEnabled )
                _logger.WarnFormat(message, args);
        }

        public void Error(string message, params object[] args)
        {
            if( _logger.IsErrorEnabled )
                _logger.ErrorFormat(message, args);
        }

        public void Fatal(string message, params object[] args)
        {
            if( _logger.IsFatalEnabled )
                _logger.FatalFormat(message, args);
        }

        public void Exception(string message, Exception exception)
        {
            if (_logger.IsErrorEnabled)
                _logger.Error(message, exception);
        }

        public void Exception(Exception exception)
        {
            if (_logger.IsErrorEnabled)
                _logger.Error("", exception);
        }
 
    }
}
